package utils

import (
	"fmt"
	"time"
)

// 计算时间差
func DateDiff(t1 time.Time) string {
	t2 := time.Now()
	diff := t2.Sub(t1)
	seconds := diff.Seconds()

	if seconds < 60 {
		return "刚刚"
	} else if seconds < 3600 {
		minutes := int(seconds / 60)
		return fmt.Sprintf("%d分钟前", minutes)
	} else if seconds < 86400 {
		hours := int(seconds / 3600)
		return fmt.Sprintf("%d小时前", hours)
	} else if seconds < 604800 {
		days := int(seconds / 86400)
		return fmt.Sprintf("%d天前", days)
	} else if seconds < 2419200 {
		weeks := int(seconds / 604800)
		return fmt.Sprintf("%d周前", weeks)
	}
	if t1.Year() != t2.Year() {
		return t1.Format("2006-01-02")
	}

	return fmt.Sprintf("%d月%d日", t1.Month(), t1.Day())
}
